import axios from "@/libs/api.request";

const prefix = "/web/sys/user";
const userApi = {
  loginE(mail, password) {
    
    const data = {
      mail,
      password,
    };
    
    return axios.request({
      url: "/web/mailLogin",
      // url: "/web/login",
      data: data,
      method: "post",
    });
  },

  login(phone, password) {
    const data = {
      phone,
      password,
    };
    
    return axios.request({
      url: "/web/login",
      data: data,
      method: "post",
    });
  },

  getUserInfo(token) {
    return axios.request({
      url: "/web/getUserInfo",
      params: {
        token,
      },
      method: "get",
    });
  },

  logout(token) {
    return axios.request({
      url: "/web/logout",
      params: {
        token,
      },
      method: "post",
    });
  },

  pageResult(user) {
    return axios.request({
      url: prefix + "/pageResult",
      data: user,
      method: "post",
    });
  },

  search(userId, enName) {
    return axios.request({
      url: prefix + "/search",
      params: { userId: userId, enName: enName },
      method: "post",
    });
  },
  searchMember(enName) {
    return axios.request({
      url: prefix + "/searchMember",
      params: { enName: enName },
      method: "post",
    });
  },

  levelPeople(id, level) {
    return axios.request({
      url: prefix + "/id/" + id + "/level/" + level,
      method: "put",
      // data: user
    });
  },
  saveOrUpdate(user) {
    return axios.request({
      url: prefix + "/saveOrUpdate",
      method: "put",
      data: user,
    });
  },
  saveOrUpdateMail(user) {
    return axios.request({
      url: prefix + "/mail/saveOrUpdate",
      method: "put",
      data: user,
    });
  },
  delete(id) {
    return axios.request({
      url: prefix + "/" + id,
      method: "delete",
    });
  },
  resetPwd(id, pwd, cmfpwd) {
    let params = { pwd: pwd, cmfpwd: cmfpwd };
    return axios.request({
      url: prefix + "/resetPwd/" + id,
      method: "put",
      params: params,
    });
  },
  changeSelfPwd(oldPwd, pwd, cmfPwd) {
    let params = { oldPwd: oldPwd, pwd: pwd, cmfPwd: cmfPwd };
    return axios.request({
      url: prefix + "/changeSelfPwd",
      method: "post",
      params: params,
    });
  },

  bindUserRole(userId, roleIds) {
    let params = { userId: userId, roleIds: roleIds };
    return axios.request({
      url: prefix + "/bindUserRole",
      method: "post",
      params: params,
    });
  },
  memberList() {
    return axios.request({
      url: prefix + "/memberList",
      method: "get",
    });
  },
  updatePersonalInfo(user) {
    return axios.request({
      url: prefix + "/personalInfo",
      method: "post",
      data: user,
    });
  },
};

export default userApi;
